#cs ----------------------------------------------------------------------------
	
	$Author: bjoern.kaiser $
	$LastChangedDate: 2008-05-05 13:40:01 +0000 (Mon, 05 May 2008) $
	
	Script Function:
	Main component
	
#ce ----------------------------------------------------------------------------

#tidy_parameters=/gd

Opt("MustDeclareVars", 1)

#NoTrayIcon

#include ".\lib\drvscan.au3"
#include ".\lib\globals.au3"
#include ".\lib\wmi.au3"

#include ".\lib\7z.au3"
#include ".\lib\bootsect.au3"
#include ".\lib\diskpart.au3"
#include ".\lib\driver.au3"
#include ".\lib\hal.au3"
#include ".\lib\hdcinject.au3"
#include ".\lib\imagex.au3"
#include ".\lib\infscan.au3"
#include ".\lib\inihandler.au3"
#include ".\lib\log.au3"
#include ".\lib\reg.au3"
#include ".\lib\workaround.au3"

If Not $gStrSourceDrv Then
	Exit 1
EndIf

Func _install()
	Local $strDevicePath
	Local $arrDrvFolders
	Local $arrHdcInf
	Local $arrInfFolders
	Local $intNumCpus = EnvGet("NUMBER_OF_CPUS")
	Local $strProcessorId = EnvGet("PROCESSOR_IDENTIFIER")
	Local $strCpuVendor = StringRegExpReplace($strProcessorId,"(?i:.*?(Intel|AMD)$)","$1")

;~ systemdaten sammeln (globals.au3)

;~ partitionieren
	_diskpart()

;~ image anwenden
	_imagex_apply($gStrSourceDrv & _ini("IMAGE", "PATH"), _ini("CONFIG", "TARGET"), 1)

;~ bootsektor schreiben
	_bootsect()

;~ hal austauschen
	_hal_swap($intNumCpus, _ini("IMAGE", "HAL"))
	
;~ treiber kopieren und ordner durchsuchen
	_driver_Copy(_ini("CONFIG", "DRIVERDIR"))
	$arrDrvFolders = _InfScan_Folders(_ini("CONFIG", "DRIVERDIR"))
	$arrInfFolders = _InfScan_HasInf($arrDrvFolders)
	$arrHdcInf = _InfScan_InfType($arrDrvFolders)

	For $item In $arrInfFolders
		If $item Then
;~ 			$item = StringTrimLeft($item, 3)
			$strDevicePath &= $item & ";"
		EndIf
	Next

;~ sata treiber integrieren
	_HdcInject($arrHdcInf, _ini("CONFIG", "TARGET") & "\Windows")

;~ write DevicePath to target registry
	_reg_Load(_ini("CONFIG", "TARGET"))
	_driver_DevicePathWrite($strDevicePath)
	_workaround_CpuDrivers($strCpuVendor)
	_reg_UnLoad()
	
;~ sysprep konfiguration schreiben
;~ (PC-Name, IP, etc.)
;~ 	IniWrite($gStrSysprepInf, "Unattended", "OemPnPDriversPath", $strSysprepDrivers)

EndFunc   ;==>_install

Func OnAutoItExit()
	FileClose($gHndLog)
	
	;~ copy logfile to system partition
	FileCopy($gStrLogfile,_ini("CONFIG", "TARGET"))
	
	;~ auto-reboot
	If Not $gBinTest Then 
		If _ini("CONFIG","AUTOREBOOT") = 1 Then Run("wpeutil reboot")
	EndIf
	
EndFunc   ;==>OnAutoItExit

_install()
